
#include <iostream>

using namespace std;

int main()
{
    int a = 10;
    int b = 20;
    a = a ^ 0;
    //a = a * a;
    cout << a << endl;
    return 0;
}

//交换两个数.
int main()
{
	int a = 10;
	int b = 20;
	a = a ^ b;
	b = a ^ b; // a ^ b ^ b = 0 ^ a = a;
	a = a ^ b; // a ^ b ^ a = b ^ 0 = b;
	cout << a << " " << b;
	return 0;
}

int main()
{
	int num = 3;
	int count = 0;
	while (num)
	{
		if (num % 2 == 1)
			count++;
		num = num / 2;
	}
	cout << "二进制中1的个数是: " << count << endl;
}

int main()
{
	int num = 3;
	int count = 0;
	for (int i = 0; i < 32; i++)
	{
		if (num & (1 << i))
		{
			count++;
		}
	}
	cout << "二进制中1的个数是: " << count << endl;
	return 0;
}

int main()
{
    int num = 3;
    int count = 0;
    while (num)
    {
        count++;
        num = num & (num - 1);
    }
    cout << "二进制中1的个数是: " << count << endl;
    return 0;
}

#include <stdio.h>
void test1(int arr[])
{
	printf("%d\n", sizeof(arr));//(2)
}

void test2(char ch[])
{
	printf("%d\n", sizeof(ch));//(4)
}

int main()
{
	int arr[10] = { 0 };
	char ch[10] = { 0 };
	printf("%d\n", sizeof(arr));//(1) 40
	printf("%d\n", sizeof(ch));//(3) 10
	test1(arr);//4/8
	test2(ch);//4/8
	return 0;
}

#include <stdio.h>
int main()
{
	int a = 10;
	//int x = ++a;
	int x = a--;
	cout << x << endl;
	cout << a << endl;
		//先对a进行自增，然后对使用a，也就是表达式的值是a自增之后的值。x为11。
	int y = --a;
	//先对a进行自减，然后对使用a，也就是表达式的值是a自减之后的值。y为10;
	return 0;
}

int main()
{
	int i = 0, a = 0, b = 2, c = 3, d = 4;
	// a = 1 b = 2 d = 4 c = 3
	i = a++ && ++b && d++;
	//i = a++||++b||d++;
	printf("a = %d\n b = %d\n c = %d\nd = %d\n", a, b, c, d);
	return 0;
}

int main()
{
    //a和b都要进行整形提升.
	char a = 0xb6;
	short b = 0xb600;
	int c = 0xb6000000;
	if (a == 0xb6)
		printf("a");
	if (b == 0xb600)
		printf("b");
	if (c == 0xb6000000)
		printf("c");
	return 0;
}

int main()
{
	char c = 1;
	printf("%u\n", sizeof(c));
	//进行整形提升了.
	printf("%u\n", sizeof(+c));
	printf("%u\n", sizeof(-c));
	return 0;
}

int main()
{
	int n = 0x11223344;
	char* pc = (char*)&n;
	int* pi = &n;
	*pc = 0; //重点在调试的过程中观察内存的变化。
	*pi = 0; //重点在调试的过程中观察内存的变化。
	return 0;
}

#include <stdio.h>
int main()
{
	int* p;  //局部变量指针未初始化，默认为随机值
	*p = 20;
	return 0;
}

#include <stdio.h>
int main()
{
	int arr[10] = { 0 };
	int* p = arr;
	int i = 0;
	for (i = 0; i <= 11; i++)
	{
		//当指针指向的范围超出数组arr的范围时，p就是野指针
		*(p++) = i;
	}
	return 0;
}

int main()
{
#define N_VALUES 5
	float values[N_VALUES];
	float* vp;
	//指针+-整数；指针的关系运算
	for (vp = &values[0]; vp < &values[N_VALUES];)
	{
		*vp++ = 0;
	}
	return 0;
}

int main()
{
	int arr[] = { 1,2,3,4,5,6,7,8,9,0 };
	int* p = arr; //指针存放数组首元素的地址
	int sz = sizeof(arr) / sizeof(arr[0]);
	for (int i = 0; i < sz; i++)
	{
		printf("&arr[%d] = %p   <====> p+%d = %p\n", i, &arr[i], i, p + i);
	}
	return 0;
}


int main()
{
	int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
	int* p = arr; //指针存放数组首元素的地址
	int sz = sizeof(arr) / sizeof(arr[0]);
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", *(p + i));
	}
	return 0;
}


struct S
{
	int data[1000];
	int num;
};
struct S s = { {1,2,3,4}, 1000 };
//结构体传参
void print1(struct S s)
{
	printf("%d\n", s.num);
}
//结构体地址传参
void print2(struct S* ps)
{
	printf("%d\n", ps->num);
}
int main()
{
	print1(s);  //传结构体
	print2(&s); //传地址
	return 0;
}


#include <stdio.h>
int main()
{
	char* p = (char*)"hello bit.";
	printf("%s\n", p);
	return 0;
}

int main()
{
	int i = 0;
	int sum = 0;//保存最终结果
	int n = 0;
	scanf("%d", &n);
	for (i = 1; i <= n; i++)
	{
		int j = 0;
		int ret = 1;
		for (j = 1; j <= i; j++)
		{
			ret *= j;
		}
		sum += ret;
	}
	printf("%d\n", sum);
	return 0;
}

#include <assert.h>

int my_strlne(const char* str)
{
	int count = 0;
	assert(str != nullptr);
	while(*str)
	{
		count++;
		str++;
	}
	return count;
}


int main()
{
	const char* str = "abcd";
	int len = my_strlne(str);
	cout << "len = " << len;
	return 0;
}

int check_sys()
{
	int i = 1;
	return (*(char*)&i);
}

int main()
{
	int ret = check_sys();
	if (ret == 1)
		cout << "小端" << endl;
	else
		cout << "大端" << endl;
	return 0;
}

int check_sys()
{
	union
	{
		int i;
		char c;
	}un;

	un.i = 1;
	return un.c;
}


int main()
{
	int ret = check_sys();
	//	int ret = check_sys();
	if (ret == 1)
		cout << "小端" << endl;
	else
		cout << "大端" << endl;
	return 0;
}


int main()
{
	char a = -1;
	//1000 0000 0000 0000 0000 0000 0000 0001;
	//1111 1111 1111 1111 1111 1111 1111 1110;
	//1111 1111 1111 1111 1111 1111 1111 1111.
	//1111 1111 1111 1111;内存存储.
	//%d打印整形:
	//1111 1111 1111 1111 1111 1111 1111 1111;
	//1111 1111 1111 1111 1111 1111 1111 1110;
	//1000 0000 0000 0000 0000 0000 0000 0001;
	//就是-1.
	signed char b = -1;
	//上面一样.
	unsigned char c = -1;
	//0000 0000 0000 0000 1111 1111 1111;
	//%d打印整形不需要截断, 然后无符号整形就是原码反码补码
	//都是一样的.
	//0000 0000 0000 0000 1111 1111 1111;
	printf("a= %d, b=%d, c=%d", a, b, c);
	return 0;
}

int main()
{
	char a = -128;
	//1000 0000 0000 0000 0000 0000 1000 0000;
	//1111 1111 1111 1111 1111 1111 0111 1111;
	//1111 1111 1111 1111 1111 1111 1000 0000;
	//%u无符号整形直接输出. 4294967168
	printf("%u\n", a);
}


int main()
{
	char a = 128;
	//0000 0000 0000 0000 0000 0000 1000 0000;
	//1000 0000; 
	//%u, 1进行补齐;
	//1111 1111 1111 1111 1111 1111 1000 0000;
	//4294967168
	printf("%u\n", a);
	return 0;
}

int main()
{
	int i = -20;
	//1000 0000 0000 0000 0000 0001 0100;
	//1111 1111 1111 1111 1111 1110 1011;
	//1111 1111 1111 1111 1111 1110 1100;

	//0000 0000 0000 0000 0000 0000 1010;
	//i+j;
	//1111 1111 1111 1111 1111 1111 0110;
	//1000 0000 0000 0000 0000 0000 1001;
	//-10;
	unsigned int j = 10;
	printf("%d\n", i + j);
	return 0;
}

int main()
{
	unsigned int i;
	for (i = 9; i >= 0; i--)
	{
		//0000 0000 0000 0000 0000 0000 0000 1001;9
		//0000 0000 0000 0000 0000 0000 0000 1000;8
		//0000 0000 0000 0000 0000 0000 0000 0111;7
		//0000 0000 0000 0000 0000 0000 0000 0110;6
		//0000 0000 0000 0000 0000 0000 0000 0101:5
		//0000 0000 0000 0000 0000 0000 0000 0100:4
		//0000 0000 0000 0000 0000 0000 0000 0011:3
		//0000 0000 0000 0000 0000 0000 0000 0010;2
		//0000 0000 0000 0000 0000 0000 0000 0001;1
		//0000 0000 0000 0000 0000 0000 0000 0000;0;
		//1000 0000 0000 0000 0000 0000 0000 0001;-1
		//1111 1111 1111 1111 1111 1111 1111 1111;-1补码;
		//4,294,967,295;
		//....
		printf("%u\n", i);
	}
	return 0;
}

// int main()
// {
// 	char a[1000];
// 	int i;
// 	for (i = 0; i < 1000; i++)
// 	{
// 		//-1; -2; -3; -4; ...; -128;
// 		//127, 126, 125, ... 0.
// 		//只能存放0-127;-1~-128;
// 		//就是255个数.
// 		a[i] = -1 - i;
// 	}
// 	printf("%d", strlen(a));
// 	return 0;
// }

unsigned char i = 0;
int main()
{
	//i的大小范围就是0-255.
	for (i = 0; i <= 255; i++)
	{
		printf("hello world\n");
	}
	return 0;
}

int main()
{
	int n = 9;
	//0000 0000 0000 0000 0000 0000 0000 1001;
	float* pFloat = (float*)&n;
	printf("n的值为：%d\n", n);
	printf("*pFloat的值为：%f\n", *pFloat);
	//0 00000000 0000 0000 0000 0000 0001 001;
	//E都是0, 那么-126;
	//M= 0.0000000000000000001001;
	//(-1)^0 * 0.0000000000000000001001 * 2 ^ (-126);
	//这个数极小.



	*pFloat = 9.0;
	//1001.0;
	//(-1)^0 * 1.001 * 2^3;
	//3 + 127 = 130 -> 1000 0010.
	//只有小数位置: 001.
	// 0 10000010 00100000000000000000000	//-1,091,567,616
	printf("num的值为：%d\n", n);
	printf("*pFloat的值为：%f\n", *pFloat);
	return 0;
}


int main()
{
	char ch = 'w';
	char* pc = &ch;
	*pc = 's';
	cout << ch << endl;
	return 0;
}

int main()
{
	const char* pstr = "hello bit.";//这里是把一个字符串放到pstr指针变量里了吗？
	printf("%s\n", pstr);
	return 0;
}

#include <stdio.h>
int main()
{
	char str1[] = "hello bit.";
	char str2[] = "hello bit.";
	const char* str3 = "hello bit.";
	const char* str4 = "hello bit.";
	if (str1 == str2)
		printf("str1 and str2 are same\n");
	else
		printf("str1 and str2 are not same\n");

	if (str3 == str4)
		printf("str3 and str4 are same\n");
	else
		printf("str3 and str4 are not same\n");

	return 0;
}

#include <stdio.h>
int main()
{
	int arr[10] = { 0 };
	printf("%p\n", arr);
	printf("%p\n", &arr);
	return 0;
}


#include <stdio.h>
int main()
{
	int arr[10] = { 0 };
	printf("arr = %p\n", arr);
	printf("&arr= %p\n", &arr);
	printf("arr+1 = %p\n", arr + 1);
	printf("&arr+1= %p\n", &arr + 1);
	return 0;
}

#include <stdio.h>
int main()
{
	int arr[10] = { 1,2,3,4,5,6,7,8,9,0 };
	int(*p)[10] = &arr;//把数组arr的地址赋值给数组指针变量p
	//但是我们一般很少这样写代码
	return 0;
}


#include <stdio.h>
void print_arr1(int arr[3][5], int row, int col)
{
	int i = 0;
	for (i = 0; i < row; i++)
	{
		for (int j = 0; j < col; j++)
		{
			printf("%d ", arr[i][j]);
		}
		printf("\n");
	}
}

void print_arr2(int(*arr)[5], int row, int col)
{
	int i = 0;
	for (i = 0; i < row; i++)
	{
		for (int j = 0; j < col; j++)
		{
			printf("%d ", arr[i][j]);
		}
		printf("\n");
	}
}
int main()
{
	int arr[3][5] = { 1,2,3,4,5,6,7,8,9,10 };
	print_arr1(arr, 3, 5);
	//数组名arr，表示首元素的地址
	//但是二维数组的首元素是二维数组的第一行
	//所以这里传递的arr，其实相当于第一行的地址，是一维数组的地址
	//可以数组指针来接收
	print_arr2(arr, 3, 5);
	return 0;
}

#include <stdio.h>
void test(int arr[])//ok?
{}
void test(int arr[10])//ok?
{}
void test(int* arr)//ok?
{}
void test2(int* arr[20])//ok?
{}
void test2(int** arr)//ok?
{}
int main()
{
	int arr[10] = { 0 };
	int* arr2[20] = { 0 };
	test(arr);
	test2(arr2);
}

// void test(int arr[3][5])//ok？
// {}
// void test(int arr[][])//ok？这个不可以没表明行多少.
// {}
// void test(int arr[][5])//ok？
// {}
//总结：二维数组传参，函数形参的设计只能省略第一个[]的数字。
//因为对一个二维数组，可以不知道有多少行，但是必须知道一行多少元素。
//这样才方便运算。
void test(int *arr)//ok？
{}
void test(int* arr[5])//ok？
{}
void test(int (*arr)[5])//ok？
{}
void test(int **arr)//ok？
{}
int main()
{
 int arr[3][5] = {0};
 test(arr);
}

#include <stdio.h>
void print(int* p, int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d\n", *(p + i));
	}
}
int main()
{
	int arr[10] = { 1,2,3,4,5,6,7,8,9 };
	int* p = arr;
	int sz = sizeof(arr) / sizeof(arr[0]);
	//一级指针p，传给函数
	print(p, sz);
	return 0;
}

void test(int** ptr)
{
	printf("num = %d\n", **ptr);
}

int main()
{
	int n = 10;
	int* p = &n;
	int** pp = &p;
	test(pp);
	test(&p);
	return 0;
}

void test(char** p)
{

}

int main()
{
	char c = 'b';
	char* pc = &c;
	char** ppc = &pc;
	char* arr[10];
	test(&pc);
	test(ppc);
	test(arr);
}

#include <stdio.h>
int add(int a, int b)
{
	return a + b;
}
int sub(int a, int b)
{
	return a - b;
}
int mul(int a, int b)
{
	return a * b;
}
// int div(int a, int b)
// {
// 	return a / b;
// }
// int main()
// {
// 	int x, y;
// 	int input = 1;
// 	int ret = 0;
// 	int(*p[5])(int x, int y) = { 0, add, sub, mul, div }; //转移表
// 	while (input)
// 	{
// 		printf("*************************\n");
// 		printf(" 1:add           2:sub \n");
// 		printf(" 3:mul           4:div \n");
// 		printf("*************************\n");
// 		printf("请选择：");
// 		scanf("%d", &input);
// 		if ((input <= 4 && input >= 1))
// 		{
// 			printf("输入操作数：");
// 			scanf("%d %d", &x, &y);
// 			ret = (*p[input])(x, y);
// 		}
// 		else
// 			printf("输入有误\n");
// 		printf("ret = %d\n", ret);
// 	}
// 	return 0;
// }

void test(const char* str)
{
	printf("%s\n", str);
}
int main()
{
	//函数指针pfun
	void (*pfun)(const char*) = test;

	//函数指针的数组pfunArr
	void (*pfunArr[5])(const char* str);
	pfunArr[0] = test;
	//指向函数指针数组pfunArr的指针ppfunArr
	void (*(*ppfunArr)[5])(const char*) = &pfunArr;
	return 0;
}

int main()
{
	int a[] = { 1,2,3,4 };
	printf("%d\n", sizeof(a));   //整个数组大小.16.
	printf("%d\n", sizeof(a + 0));// 首元素地址大小; 4/8;
	printf("%d\n", sizeof(*a));  //第一个元素的大小; 4;
	printf("%d\n", sizeof(a + 1)); //第二个元素地址大小; 4/8
	printf("%d\n", sizeof(a[1])); // 第二个元素的大小, 4
	printf("%d\n", sizeof(&a));	//全部元素的地址大小, 4/8
	printf("%d\n", sizeof(*&a));  //全部元素的大小; 16
	printf("%d\n", sizeof(&a + 1));  // 整个元素地址跳过一个数组的指针大小, 4/8;
	printf("%d\n", sizeof(&a[0]));  //第一个元素地址的大小, 4/8;
	printf("%d\n", sizeof(&a[0] + 1)); // 第二个元素地址大小, 4/8
	return 0;
}

int main()
{
	//char arr[] = { 'a','b','c','d','e','f' };
	//printf("%d\n", sizeof(arr)); //整个元素的大小; 6.
	//printf("%d\n", sizeof(arr + 0)); //第一个元素地址的大小, 4/8;
	//printf("%d\n", sizeof(*arr)); //第一个元素的大小: 1;
	//printf("%d\n", sizeof(arr[1])); //第二个元素的大小: 1;
	//printf("%d\n", sizeof(&arr));	//整个数组的地址的大小; 4/8;
	//printf("%d\n", sizeof(&arr + 1));	//跳过整个数组的大小的地址. 4/8;
	//printf("%d\n", sizeof(&arr[0] + 1));	//第二个元素的地址大小`.4/8

	//printf("%d\n", strlen(arr)); //因为没有\0不知道是多少值.
	//printf("%d\n", strlen(arr + 0));	//随机值.
	//printf("%d\n", strlen(*arr));	//首元素的值进行取出字符串大小, 肯定不对.
	//printf("%d\n", strlen(arr[1])); //不对;
	//printf("%d\n", strlen(&arr));	//整个数组地址, 也是随机值.
	//printf("%d\n", strlen(&arr + 1));	//跳过一个数组也是随机值.
	//printf("%d\n", strlen(&arr[0] + 1));	//随机值.


	char arr[] = "abcdef";
	//printf("%d\n", sizeof(arr)); //整个数组大小, 7包括\0.
	//printf("%d\n", sizeof(arr + 0));  //首元素地址, 4/8;
	//printf("%d\n", sizeof(*arr));  //首个元素; 1;
	//printf("%d\n", sizeof(arr[1]));  //第二个元素; 1;
	//printf("%d\n", sizeof(&arr));	//整个数组的地址, 4/8;
	//printf("%d\n", sizeof(&arr + 1));	//整个数组跳过一个数组的地址; 4/8;
	//printf("%d\n", sizeof(&arr[0] + 1));	//数组跳过一个元素的地址, 4/8;


	//printf("%d\n", strlen(arr));	//字符串的大小, 6;
	//printf("%d\n", strlen(arr + 0)); //字符串大小, 6.
	////printf("%d\n", strlen(*arr));	//不对, 第一个元素取出长度.
	////printf("%d\n", strlen(arr[1]));//不对.
	////printf("%d\n", strlen(&arr));//整个数组的地址.6
	////printf("%d\n", strlen(&arr + 1));// 随机值.
	//printf("%d\n", strlen(&arr[0] + 1));//跳过第一个元素的地址. 5.

	const char* p = "abcdef";
	//printf("%d\n", sizeof(p)); //指针大小: 4/8
	//printf("%d\n", sizeof(p + 1)); //指针跳过第一个的地址. 4/8;
	//printf("%d\n", sizeof(*p));//首字符串大小, 7
	//printf("%d\n", sizeof(p[0])); //第一个元素的大小, 1.
	//printf("%d\n", sizeof(&p));//指针地址; 4/8
	//printf("%d\n", sizeof(&p + 1));  //指针跳过一个字符串; 4/8
	//printf("%d\n", sizeof(&p[0] + 1));  //指针跳过一个元素的地址.//4/8

	//printf("%d\n", strlen(p));	//6
	//printf("%d\n", strlen(p + 1));  //5
	////printf("%d\n", strlen(*p)); //不对
	////printf("%d\n", strlen(p[0])); //不对.
	////printf("%d\n", strlen(&p));不对.
	////printf("%d\n", strlen(&p + 1));//随机值.
	//printf("%d\n", strlen(&p[0] + 1));//5

	int a[3][4] = { 0 };
	printf("%d\n", sizeof(a)); //整个数组大小: 48.
	printf("%d\n", sizeof(a[0][0])); //第一个元素的大小. 4.
	printf("%d\n", sizeof(a[0]));   //第一行一维数组名. 16
	printf("%d\n", sizeof(a[0] + 1));	//第一行第一个元素;  4
	printf("%d\n", sizeof(*(a[0] + 1)));  // 第一行第一个元素的地址大小: 4/8
	printf("%d\n", sizeof(a + 1));	//首数组的地址+1第二行数组的地址.4/8;
	printf("%d\n", sizeof(*(a + 1))); //第二行数组的大小; //16;
	printf("%d\n", sizeof(&a[0] + 1));//第二行数组地址 4/8
	printf("%d\n", sizeof(*(&a[0] + 1)));  //第二行数组的大小; 16
	printf("%d\n", sizeof(*a));		//第一行数组的大小; 16;
	printf("%d\n", sizeof(a[3]));	//第四行数组大小, 16.

	return 0;
}


int main()
{
	int a[5] = { 1, 2, 3, 4, 5 };
	int* ptr = (int*)(&a + 1);
	//2, 5
	printf("%d,%d", *(a + 1), *(ptr - 1));
	return 0;
}

struct Test
{
	int Num;
	char* pcName;
	short sDate;
	char cha[2];
	short sBa[4];
}*p;


//假设p 的值为0x100000。 如下表表达式的值分别为多少？
//已知，结构体Test类型的变量大小是20个字节
int main()
{
	//0x100014;20十六进制为14, 就是跳过全部大小.
	printf("%p\n", p + 0x1);
	//0x100001;
	printf("%p\n", (unsigned long)p + 0x1);
	//0x100004;
	printf("%p\n", (unsigned int*)p + 0x1);
	return 0;
}

int main()
{
	int a[4] = { 1, 2, 3, 4 };
	int* ptr1 = (int*)(&a + 1);
	int* ptr2 = (int*)((int)a + 1);
	//4, 2000000 (int)a+1就是跳过首元素的一个字节.还有三个字节都是0, 然后又是小端读出来就是2 00 00 00.
	printf("%x,%x", ptr1[-1], *ptr2);
	return 0;
}


#include <stdio.h>
int main()
{

	//逗号表达式是取最后一个值.
	int a[3][2] = { (0, 1), (2, 3), (4, 5) };
	int* p;
	p = a[0];
	printf("%d", p[0]);
	return 0;
}

int main()
{
	int a[5][5];
	int(*p)[4];
	//-4: 1000 0000 0000 0000 0000 0000 0000 0100
	//    1111 1111 1111 1111 1111 1111 1111 1100
	//		F   F   F    F   F  F F C
	p = a;
	//FFFFFFFC -4.
	printf("%p,%d\n", &p[4][2] - &a[4][2], &p[4][2] - &a[4][2]);
	return 0;
}


int main()
{
	int aa[2][5] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
	int* ptr1 = (int*)(&aa + 1);
	int* ptr2 = (int*)(*(aa + 1));
	//10 5
	printf("%d,%d", *(ptr1 - 1), *(ptr2 - 1));
	return 0;
}


#include <stdio.h>
int main()
{
	const char* a[] = { "work","at","alibaba" };
	const char** pa = a;
	pa++;
	//char* 到at.
	printf("%s\n", *pa);
	return 0;
}


#include <stdio.h>
int main()
{
	const char* str1 = "abcdef";
	const char* str2 = "bbb";
	//因为是无符号类型, 大小比不出来.
	if (strlen(str2) - strlen(str1) > 0)
	{
		printf("str2>str1\n");
	}
	else
	{
		printf("srt1>str2\n");
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
int main()
{
	char str[] = "This is a simple string";
	char* pch;
	pch = strstr(str, "simple");
	strncpy(pch, "sample", 6);
	puts(str);
	return 0;
}

#include <stdio.h>
#include <string.h>
int main()
{
	char str[] = "- This, a sample string.";
	char* pch;
	printf("Splitting string \"%s\" into tokens:\n", str);
	pch = strtok(str, " ,.-");
	while (pch != NULL)
	{
		printf("%s\n", pch);
		pch = strtok(NULL, " ,.-");
	}
	return 0;
}

int my_strlen(const char* str)
{
	int count = 0;
	while (*str)
	{
		count++;
		str++;
	}
	return count;
}

char* my_strcpy(char* dest, const char* src)
{
	char* ret = dest;
	assert(dest != nullptr);
	while (*dest++ = *src++)
	{
		;
	}
	return ret;
}


char* my_strcat(char* dest, char* src)
{
	char* ret = dest;
	assert(dest != nullptr);
	assert(src != nullptr);
	while (*dest)
		dest++;
	while (*dest++ = *src++)
	{
		;
	}
	return ret;
}

char* my_strstr(const char* str1, const char* str2)
{
	//strstr("helloworld", "hello");
	//        cp
	//        s1            s2
	char* cp = (char*)str1;
	char* s1, * s2;

	if (!*str2)
		return (char*)str1;

	while (*cp)
	{
		s1 = cp;
		s2 = (char*)str2;

		while (*s1 && *s2 && !(str1 - *str2))
		{
			s1++;
			s2++;
		}

		//s2遍历完成.返回cp指针.
		if (!*s2)
			return cp;
		cp++;
	}
	return nullptr;
}

void* memcpy(void* dest, const void* src, size_t count)
{
	void* ret = dest;
	assert(dest);
	assert(src);

	while (count--)
	{
		*(char*)dest = *(char*)src;
		dest = (char*)dest + 1;
		src = (char*)src + 1;
	}
	return ret;
}


void* memmove(void* dest, void* src, size_t count)
{
	// dest: "nihao"    src: "world i love you"
	void* ret = dest;
	//防止覆盖.
	if (dest <= src || (char*)dest >= ((char*)src + count))
	{
		while (count--)
		{
			*(char*)dest = *(char*)src;
			dest = (char*)dest + 1;
			src = (char*)src + 1;
		}
	}
	else
	{
		//有重叠就从后到前进行覆盖.
		dest = (char*)dest + count - 1;
		src = (char*)src + count - 1;
		while (count--)
		{
			*(char*)dest = *(char*)src;
			dest = (char*)dest - 1;
			src = (char*)src - 1;
		}
	}
}